package com.admin.work.domain;

import com.admin.common.annotation.Excel;
import com.admin.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.text.DecimalFormat;
import java.util.Date;

public class WorkBuyInfo extends BaseEntity {
    private static final long serialVersionUID = 1L;

    @Excel(name = "ID")
    private Integer ID;

    @Excel(name = "姓名")
    private String nickName;

    @Excel(name = "标的代码")
    private String code;

    @Excel(name = "标的名称")
    private String codeName;

    @Excel(name = "名义本金")
    private Integer benjin;

    @Excel(name = "费率")
    private Double rate;

    /**
     * 名义本金(benjin) * 费率(rate) * 10000
     */
    @Excel(name = "期权费")
    private Double amount;

    // 到期日 - 起始日
    @Excel(name = "天数")
    private Integer days;

    @Excel(name = "起始日")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startDate;

    @Excel(name = "到期日")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    @Excel(name = "成交价")
    private Double cj;

    @Excel(name = "结构")
    private Long struct;

    /**
     * 成交价 * 结构 / 100
     */
    @Excel(name = "执行价")
    private Double zxj;

    @Excel(name = "现价")
    private Double xj;

    /**
     * (名义本金(benjin) * 10000 / 成交价(price1)) * (现价(price3) - 成交价(price1)) -
     * (结构(struct) - 100) * 100 * 名义本金(benjin)
     */
    @Excel(name = "参考净收益")
    private Double sy;

    @Excel(name = "对手方")
    private String dsf;

    @Excel(name = "备注")
    private String mark;

    private Long deptID;

    private Long userID;

    private Boolean own;

    public Integer getID() {
        return ID;
    }

    public void setID(Integer ID) {
        this.ID = ID;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCodeName() {
        return codeName;
    }

    public void setCodeName(String codeName) {
        this.codeName = codeName;
    }

    public Integer getBenjin() {
        return benjin;
    }

    public void setBenjin(Integer benjin) {
        this.benjin = benjin;
    }

    public Double getRate() {
        return rate;
    }

    public void setRate(Double rate) {
        this.rate = rate;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount() {
        // 名义本金(benjin) * 费率(rate) * 10000
        this.amount = this.benjin * this.rate * 10000;

        DecimalFormat df = new DecimalFormat("#.00");
        String formatValue = df.format(this.amount);
        this.amount = Double.valueOf(formatValue);
    }

    public Integer getDays() {
        return days;
    }

    public void setDays(Integer days) {
        this.days = days;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Double getCj() {
        return cj;
    }

    public void setCj(Double cj) {
        this.cj = cj;
    }

    public Long getStruct() {
        return struct;
    }

    public void setStruct(Long struct) {
        this.struct = struct;
    }

    public Double getZxj() {
        return zxj;
    }

    public void setZxj() {
        // 成交价 * 结构 / 100
        this.zxj = this.cj * this.struct / 100;

        DecimalFormat df = new DecimalFormat("#.00");
        String formatValue = df.format(this.zxj);
        this.zxj = Double.valueOf(formatValue);
    }

    public Double getXj() {
        return xj;
    }

    public void setXj(Double xj) {
        this.xj = xj;
    }

    public Double getSy() {
        return sy;
    }

    public void setSy() {
        if(this.cj == 0 || this.cj == null || this.xj == 0 || this.xj == null) {
            this.sy = (double) 0;

            return;
        }
        /**
         * (名义本金(benjin) * 10000 / 成交价(cj)) * (现价(xj) - 成交价(cj)) -
         * (结构(struct) - 100) * 100 * 名义本金(benjin)
         *
         * (4992.51123 * -197.8) - 2000000
         */
        this.sy = (this.benjin * 10000 / this.cj) * (this.xj - this.cj) - (this.struct - 100) * 100 * this.benjin;

        DecimalFormat df = new DecimalFormat("#.00");
        this.sy = Double.valueOf(df.format(this.sy));
    }

    public String getDsf() {
        return dsf;
    }

    public void setDsf(String dsf) {
        this.dsf = dsf;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public Long getUserID() {
        return userID;
    }

    public void setUserID(Long userID) {
        this.userID = userID;
    }

    public Long getDeptID() {
        return deptID;
    }

    public void setDeptID(Long deptID) {
        this.deptID = deptID;
    }

    public Boolean getOwn() {
        return this.own;
    }

    public void setOwn(Long userID) {
        if(userID == this.userID) {
            this.own = true;
        } else {
            this.own = false;
        }
    }

    @Override
    public String toString() {

        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("ID", getID())
                .append("nickName", getNickName())
                .append("code", getCode())
                .append("codeName", getCodeName())
                .append("benjin", getBenjin())
                .append("rate", getRate())
                .append("amount", getAmount())
                .append("days", getDays())
                .append("startDate", getStartDate())
                .append("endDate", getEndDate())
                .append("cj", getCj())
                .append("struct", getStruct())
                .append("zxj", getZxj())
                .append("xj", getXj())
                .append("sy", getSy())
                .append("dsf", getDsf())
                .append("mark", getMark())
                .append("deptID", getDeptID())
                .append("userID", getUserID())
                .append("own", getOwn())
                .toString();
    }
}
